//
//  NSObject+Animal.m
//  runtime
//
//  Created by dihuijun on 17/3/30.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "NSObject+Animal.h"
#import <objc/message.h>
@implementation NSObject (Animal)

-(void)setAnimalName:(NSString *)animalName
{
    /*
     给某个对象产生关联，添加属性
     object:给哪个对象添加属性
     key:属性名，根据key去获取关联的对象，void * == id
     value : 关联的值
     policy : 策略
     */
    objc_setAssociatedObject(self, @"animalName", animalName, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
/*
 添加属性，给对象用objc_
 给类：class_
 */
-(NSString *)animalName{
    return objc_getAssociatedObject(self, @"animalName");
}

@end
